//
//  ZWelcomeViewController.m
//  OC-weibo
//
//  Created by zero on 17/3/23.
//  Copyright © 2017年 zero. All rights reserved.
//

#import "ZWelcomeViewController.h"


#define Bottom 180
#define ButtonW 85

@interface ZWelcomeViewController ()

@property (nonatomic,weak)UIImageView *imageView;

@property (nonatomic,weak)UILabel *titleLabel;
@end

@implementation ZWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor z_colorWithHex:0xf5f5f9];
    
    //  布局
    [self setupUI];
    
}

#pragma mark
#pragma mark - 布局
- (void)setupUI{
    
    //  添加头像
    UIImageView *imageView = [[UIImageView alloc] init];
    
    self.imageView = imageView;
    
    [self.view addSubview:imageView];
    
    //  约束
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-Bottom);
        
        make.size.mas_equalTo(CGSizeMake(ButtonW, ButtonW));
        
    }];
    
    
    //  huanyin
    UILabel *titleLabel = [UILabel z_labelWithText:@"欢迎回来" andFontSize:14 andColor:[UIColor blackColor]];
    
    self.titleLabel = titleLabel;
    
    [self.view addSubview:titleLabel];
    
    //  约束
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(imageView);
        make.top.equalTo(imageView.mas_bottom).offset(16);
        
    }];
    
    //  设置属性
    [imageView sd_setImageWithURL:[ZUserAccountViewModel shareUserAccountViewModel].urlImage placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    titleLabel.alpha = 0;
    
}

#pragma mark
#pragma mark - 视图显示的时候
- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    [self addAnimation];
}

#pragma mark
#pragma mark - 添加动画
- (void)addAnimation{
    
    CGFloat offset = -([UIScreen mainScreen].bounds.size.height - Bottom - ButtonW);
    
    
    [self.imageView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.view).offset(offset);
    }];
    
    [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:UIViewAnimationOptionLayoutSubviews animations:^{
        

        
    [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:2.0 animations:^{
            
            self.titleLabel.alpha = 1;
            
        } completion:^(BOOL finished) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:ChangeVC object:@(VCTypeOAuthViewController)];
        }];
        
    }];
 
    
}

@end
